/**
 * 认证状态管理模块
 */
import { defineStore } from 'pinia'
import type { TokenResult } from '@/types/auth'
/**
 * 认证状态管理模块的存储定义
 */
export const useAuthStore = defineStore('auth', {
  state: () => {
    return {
      // 初始化
      token: { access_token: localStorage.getItem('atlas-token') } as TokenResult,
    }
  },

  getters: {
    /**
     * 获取token
     */
    getToken: (state) => state.token.access_token,
  },

  actions: {
    /**
     * 设置token
     * @param token token
     */
    async setToken(token: TokenResult) {
      this.token = token
      localStorage.setItem('atlas-token', token.access_token)
    },
  },
})
